package org.deadline.model.user;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.deadline.model.baseapp.Principal;
import org.deadline.model.config.Enumeration;
import org.hibernate.annotations.ForeignKey;

@Entity
@PrimaryKeyJoinColumn(name="id")
public class UserGroup extends Principal {

    @NotNull
    @Size(min = 3, max = 255)
    private String groupName;

    @NotNull
    @Size(min = 3, max = 255)
    private String groupCode;

    @ManyToOne
    private Enumeration groupType;

    @NotNull
    @Size(min = 5, max = 1000)
    private String description;

    @NotNull
    @ManyToOne
    private Person groupOwner;

	private static final long serialVersionUID = 1L;

	public String getGroupName() {
        return this.groupName;
    }

	public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

	public String getGroupCode() {
        return this.groupCode;
    }

	public void setGroupCode(String groupCode) {
        this.groupCode = groupCode;
    }

	public Enumeration getGroupType() {
        return this.groupType;
    }

	public void setGroupType(Enumeration groupType) {
        this.groupType = groupType;
    }

	public String getDescription() {
        return this.description;
    }

	public void setDescription(String description) {
        this.description = description;
    }

	public Person getGroupOwner() {
        return this.groupOwner;
    }

	public void setGroupOwner(Person groupOwner) {
        this.groupOwner = groupOwner;
    }

	public String toJson() {
        return new JSONSerializer().exclude("*.class").deepSerialize(this);
    }

	public static UserGroup fromJsonToUserGroup(String json) {
        return new JSONDeserializer<UserGroup>().use(null, UserGroup.class).deserialize(json);
    }

	public static String toJsonArray(Collection<UserGroup> collection) {
        return new JSONSerializer().exclude("*.class").deepSerialize(collection);
    }

	public static Collection<UserGroup> fromJsonArrayToUserGroups(String json) {
        return new JSONDeserializer<List<UserGroup>>().use(null, ArrayList.class).use("values", UserGroup.class).deserialize(json);
    }
	
	
	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}
